<?php

/*
 * Action   $4
 * 
 * Gain a Silver.
 * Look at the top card of your deck; discard it or put it back.
 * Draw until you have 5 cards in hand.
 * You may trash a card from your hand that is not a Treasure.
 */

class JackOfAllTrades extends Card implements iKingdom, iHinterlands, iAction {

    public function __construct() {
        parent::__construct("Jack Of All Trades", 4);
    }

    public function getDescription() {
        return array(
            "Gain a Silver.",
            "Look at the top card of your deck; discard it or put it back.",
            "Draw until you have 5 cards in hand.",
            "You may trash a card from your hand that is not a Treasure.");
    }
	public function getDisplayName($quantity = 1) {
        if ($quantity == 1) {
            return "Jack Of All Trades";
        }
        return $quantity . " Jack Of All Trades";
    }

    public function play(Game $game, $isRealCard = true) {
        // Gain a Silver
        $silver = $game->moveCardFromPileToPile("Silver", BoardCards, DiscardPile);
        ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($silver), "gains " . ScreenDisplay::$LMSG);

        // Look at the top card of your deck; discard it or put it back
        $top_card = $game->peekCardFromDrawDeck();
        $options = array(new Option(1, "Yes"), new Option(2, "No"));
        $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Discard " . $top_card->getValue() . " from the top of the draw deck?");
        if ($output[0] == "Yes") {
            $discarded_cards = $game->discardCardsFromDrawDeck(1);
            ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($discarded_cards) . " from your deck", "discards " . sizeof($discarded_cards) . " cards from his deck");
        }
        else {
            ScreenDisplay::addScreenMessage($game, true, "leave " . nicePrint($top_card) . " on top of your deck", "leaves " . sizeof(array($top_card)) . " card on  from his deck");
        }

        // Draw until you have 5 cards in hand
        $handSize = $game->getPlayHandSize();
        $drawCardsNum = max(0, 5 - $handSize);
        $drawed_cards = $game->drawCards($drawCardsNum);
        ScreenDisplay::addScreenMessage($game, true, "draw " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards) . " cards");

        //You may trash a card from your hand that is not a Treasure
        $playHand = $game->getPlayHand();
        $options = array();
        foreach ($playHand as $card) {
            if ($card instanceof iTreasure) {
                continue;
            }
            $options[] = $card;
        }
        $options = getUniqueCards($options);

        if (sizeof($options) > 0) {
            $options[] = new Option(1, "None");
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Choose card to trash");
            $card_name = $output[0];
            if ($card_name != "None") {
                $card = $game->moveCardFromPileToPile($card_name, PlayHand, Trash);
                ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($card), "trashes " . ScreenDisplay::$LMSG);
            } else {
                ScreenDisplay::addScreenMessage($game, true, "trash nothing", "trashes nothing");
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, "trash nothing", "trashes nothing");
        }

        $game->cardActionFinished();
        return true;
    }

}

?>
